﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ERPStudio;
using System.Data.SqlClient;

namespace AMix
{
    public partial class ComponenteMFixFrm : FrmRezumat
    {
        public Int32 LunaCurenta = 0;
        public Int32 AnulCurent = 0;
        private int MFPrincipal = 0;
        public int IDDocument = 0;
        public ComponenteMFixFrm(int mfixPrincipal, ModuleClass mInfo)
            : base(mInfo)
        {
            MFPrincipal = mfixPrincipal;
            InitializeComponent();
            eSRPDataSet.AmixAnsamble.IDMFixPrincipalColumn.DefaultValue = mfixPrincipal;
        }

        private void ComponenteMFixFrm_Load(object sender, EventArgs e)
        {
            SqlConnection con = DeschideConexiune(workConnString);
            this.amixComponenteTableAdapter.Connection = con;
            this.amixComponenteTableAdapter.Fill(this.eSRPDataSet.AmixComponente, ModuleInfo.CodUnitate, MFPrincipal);
            this.amixAnsambleTableAdapter.Connection = con;
            this.amixAnsambleTableAdapter.Fill(this.eSRPDataSet.AmixAnsamble,MFPrincipal);
            InchideConexiune(con);

            this.listBndSourceMain.Add(amixAnsambleBindingSource);
            listTableAdaptor.Add(amixAnsambleTableAdapter.Adapter);
        }

        override public void Salvare(object sender, EventArgs args)
        {
            Cursor.Current = Cursors.WaitCursor;
            base.Salvare(this, args);
            SqlConnection con = DeschideConexiune(workConnString);
            if (EroareSalvare)
                return;

            if (NoRecUpdated > 0)
            {
                SqlCommand cmd = new SqlCommand("[amix_InchideLuna2]", con);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add(new SqlParameter("@Luna", LunaCurenta.ToString()));
                cmd.Parameters.Add(new SqlParameter("@An", AnulCurent.ToString()));
                cmd.Parameters.Add(new SqlParameter("@CodUnitate", ModuleInfo.CodUnitate.ToString()));
                cmd.Parameters.Add(new SqlParameter("@IDDocument", IDDocument));
                cmd.Parameters.Add(new SqlParameter("@InchideLuna", "0"));
                try
                {
                    cmd.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                    TrateazaExceptie(ex);
                }
            }
            InchideConexiune(con);
            Cursor.Current = Cursors.Default;
        }

    }
}
